﻿using System;
using System.Windows.Input;
using SpotOffer.DataModels;
using Xamarin.Forms;

namespace SpotOffer.ViewModels
{
    public class DealViewModel:BaseViewModel
    {
        public Deal SelectedDeal
        {
            get
            {
                return _selectedDeal;

            }
            set
            {
                if (value != null)
                {
                    _selectedDeal = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private Deal _selectedDeal;
     
        public string DealTitle
        {
            get { return _selectedDeal.provider+" "+_selectedDeal.discount; }
        }
        private string _dealTitle;

        public DealViewModel(Deal selectedDeal)
        {
            SelectedDeal = selectedDeal;
        }

        public UrlWebViewSource Url
        {
            get { return new UrlWebViewSource {Url = SelectedDeal.url}; }
        }

        public ICommand Open
        {
            get
            {
                return new Command((nothing) =>
                {
                    Device.OpenUri(new Uri(SelectedDeal.url));
                });
            }
        }
    }
}
